home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_elisp-manual-19.idb / usr / freeware / info / elisp-13.z / elisp-13 (.txt)
GNU Info File  |  1998-05-26  |  51KB  |  998 lines

  1. This is Info file elisp, produced by Makeinfo-1.63 from the input file
  2. elisp.texi.
  3.    This version is the edition 2.4.2 of the GNU Emacs Lisp Reference
  4. Manual.  It corresponds to Emacs Version 19.34.
  5.    Published by the Free Software Foundation 59 Temple Place, Suite 330
  6. Boston, MA  02111-1307  USA
  7.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996 Free Software
  8. Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that the
  14. entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided also
  22. that the section entitled "GNU General Public License" is included
  23. exactly as in the original, and provided that the entire resulting
  24. derived work is distributed under the terms of a permission notice
  25. identical to this one.
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that the section entitled "GNU General Public License"
  29. may be included in a translation approved by the Free Software
  30. Foundation instead of in the original English.
  31. File: elisp,  Node: Specification List,  Next: Backtracking,  Up: Instrumenting Macro Calls
  32. Specification List
  33. ..................
  34.    A "specification list" is required for an Edebug specification if
  35. some arguments of a macro call are evaluated while others are not.  Some
  36. elements in a specification list match one or more arguments, but others
  37. modify the processing of all following elements.  The latter, called
  38. "specification keywords", are symbols beginning with `&' (such as
  39. `&optional').
  40.    A specification list may contain sublists which match arguments that
  41. are themselves lists, or it may contain vectors used for grouping.
  42. Sublists and groups thus subdivide the specification list into a
  43. hierarchy of levels.  Specification keywords only apply to the
  44. remainder of the sublist or group they are contained in.
  45.    When a specification list involves alternatives or repetition,
  46. matching it against an actual macro call may require backtracking.
  47. *Note Backtracking::, for more details.
  48.    Edebug specifications provide the power of regular expression
  49. matching, plus some context-free grammar constructs: the matching of
  50. sublists with balanced parentheses, recursive processing of forms, and
  51. recursion via indirect specifications.
  52.    Here's a table of the possible elements of a specification list, with
  53. their meanings:
  54. `sexp'
  55.      A single Lisp object, not unevaluated.
  56. `form'
  57.      A single evaluated expression, which is instrumented.
  58. `place'
  59.      A place to store a value, as in the Common Lisp `setf' construct.
  60. `body'
  61.      Short for `&rest form'.  See `&rest' below.
  62. `function-form'
  63.      A function form: either a quoted function symbol, a quoted lambda
  64.      expression, or a form (that should evaluate to a function symbol or
  65.      lambda expression).  This is useful when an argument that's a
  66.      lambda expression might be quoted with `quote' rather than
  67.      `function', since it instruments the body of the lambda expression
  68.      either way.
  69. `lambda-expr'
  70.      A lambda expression with no quoting.
  71. `&optional'
  72.      All following elements in the specification list are optional; as
  73.      soon as one does not match, Edebug stops matching at this level.
  74.      To make just a few elements optional followed by non-optional
  75.      elements, use `[&optional SPECS...]'.  To specify that several
  76.      elements must all match or none, use `&optional [SPECS...]'.  See
  77.      the `defun' example below.
  78. `&rest'
  79.      All following elements in the specification list are repeated zero
  80.      or more times.  All the elements need not match in the last
  81.      repetition, however.
  82.      To repeat only a few elements, use `[&rest SPECS...]'.  To specify
  83.      several elements that must all match on every repetition, use
  84.      `&rest [SPECS...]'.
  85. `&or'
  86.      Each of the following elements in the specification list is an
  87.      alternative.  One of the alternatives must match, or the `&or'
  88.      specification fails.
  89.      Each list element following `&or' is a single alternative.  To
  90.      group two or more list elements as a single alternative, enclose
  91.      them in `[...]'.
  92. `¬'
  93.      Each of the following elements is matched as alternatives as if by
  94.      using `&or', but if any of them match, the specification fails.
  95.      If none of them match, nothing is matched, but the `¬'
  96.      specification succeeds.
  97. `&define'
  98.      Indicates that the specification is for a defining form.  The
  99.      defining form itself is not instrumented (i.e. Edebug does not
  100.      stop before and after the defining form), but forms inside it
  101.      typically will be instrumented.  The `&define' keyword should be
  102.      the first element in a list specification.
  103. `nil'
  104.      This is successful when there are no more arguments to match at the
  105.      current argument list level; otherwise it fails.  See sublist
  106.      specifications and the backquote example below.
  107. `gate'
  108.      No argument is matched but backtracking through the gate is
  109.      disabled while matching the remainder of the specifications at
  110.      this level.  This is primarily used to generate more specific
  111.      syntax error messages.  See *Note Backtracking::, for more
  112.      details.  Also see the `let' example below.
  113. `OTHER-SYMBOL'
  114.      Any other symbol in a specification list may be a predicate or an
  115.      indirect specification.
  116.      If the symbol has an Edebug specification, this "indirect
  117.      specification" should be either a list specification that is used
  118.      in place of the symbol, or a function that is called to process the
  119.      arguments.  The specification may be defined with `def-edebug-spec'
  120.      just as for macros. See the `defun' example below.
  121.      Otherwise, the symbol should be a predicate.  The predicate is
  122.      called with the argument and the specification fails if the
  123.      predicate returns `nil'.  In either case, that argument is not
  124.      instrumented.
  125.      Some suitable predicates include `symbolp', `integerp', `stringp',
  126.      `vectorp', and `atom'.
  127. `[ELEMENTS...]'
  128.      A vector of elements groups the elements into a single "group
  129.      specification".  Its meaning has nothing to do with vectors.
  130. `"STRING"'
  131.      The argument should be a symbol named STRING.  This specification
  132.      is equivalent to the quoted symbol, `'SYMBOL', where the name of
  133.      SYMBOL is the STRING, but the string form is preferred.
  134. `(vector ELEMENTS...)'
  135.      The argument should be a vector whose elements must match the
  136.      ELEMENTS in the specification.  See the backquote example below.
  137. `(ELEMENTS...)'
  138.      Any other list is a "sublist specification" and the argument must
  139.      be a list whose elements match the specification ELEMENTS.
  140.      A sublist specification may be a dotted list and the corresponding
  141.      list argument may then be a dotted list.  Alternatively, the last
  142.      CDR of a dotted list specification may be another sublist
  143.      specification (via a grouping or an indirect specification, e.g.
  144.      `(spec .  [(more specs...)])') whose elements match the non-dotted
  145.      list arguments.  This is useful in recursive specifications such
  146.      as in the backquote example below.  Also see the description of a
  147.      `nil' specification above for terminating such recursion.
  148.      Note that a sublist specification written as `(specs .  nil)' is
  149.      equivalent to `(specs)', and `(specs .  (sublist-elements...))' is
  150.      equivalent to `(specs sublist-elements...)'.
  151.    Here is a list of additional specifications that may only appear
  152. after `&define'.  See the `defun' example below.
  153. `name'
  154.      The argument, a symbol, is the name of the defining form.
  155.      A defining form is not required to have a name field; and it may
  156.      have multiple name fields.
  157. `:name'
  158.      This construct does not actually match an argument.  The element
  159.      following `:name' should be a symbol; it is used as an additional
  160.      name component for the definition.  You can use this to add a
  161.      unique, static component to the name of the definition.  It may be
  162.      used more than once.
  163. `arg'
  164.      The argument, a symbol, is the name of an argument of the defining
  165.      form.  However, lambda list keywords (symbols starting with ``&'')
  166.      are not allowed.
  167. `lambda-list'
  168.      This matches a lambda list--the argument list of a lambda
  169.      expression.
  170. `def-body'
  171.      The argument is the body of code in a definition.  This is like
  172.      `body', described above, but a definition body must be instrumented
  173.      with a different Edebug call that looks up information associated
  174.      with the definition.  Use `def-body' for the highest level list of
  175.      forms within the definition.
  176. `def-form'
  177.      The argument is a single, highest-level form in a definition.
  178.      This is like `def-body', except use this to match a single form
  179.      rather than a list of forms.  As a special case, `def-form' also
  180.      means that tracing information is not output when the form is
  181.      executed.  See the `interactive' example below.
  182. File: elisp,  Node: Backtracking,  Next: Specification Examples,  Prev: Specification List,  Up: Instrumenting Macro Calls
  183. Backtracking
  184. ............
  185.    If a specification fails to match at some point, this does not
  186. necessarily mean a syntax error will be signaled; instead,
  187. "backtracking" will take place until all alternatives have been
  188. exhausted.  Eventually every element of the argument list must be
  189. matched by some element in the specification, and every required element
  190. in the specification must match some argument.
  191.    Backtracking is disabled for the remainder of a sublist or group when
  192. certain conditions occur, described below.  Backtracking is reenabled
  193. when a new alternative is established by `&optional', `&rest', or
  194. `&or'.  It is also reenabled initially when processing a sublist or
  195. group specification or an indirect specification.
  196.    You might want to disable backtracking to commit to some alternative
  197. so that Edebug can provide a more specific syntax error message.
  198. Normally, if no alternative matches, Edebug reports that none matched,
  199. but if one alternative is committed to, Edebug can report how it failed
  200. to match.
  201.    First, backtracking is disabled while matching any of the form
  202. specifications (i.e. `form', `body', `def-form', and `def-body').
  203. These specifications will match any form so any error must be in the
  204. form itself rather than at a higher level.
  205.    Second, backtracking is disabled after successfully matching a quoted
  206. symbol or string specification, since this usually indicates a
  207. recognized construct.  If you have a set of alternative constructs that
  208. all begin with the same symbol, you can usually work around this
  209. constraint by factoring the symbol out of the alternatives, e.g.,
  210. `["foo" &or [first case] [second case] ...]'.
  211.    Third, backtracking may be explicitly disabled by using the `gate'
  212. specification.  This is useful when you know that no higher
  213. alternatives may apply.
  214. File: elisp,  Node: Specification Examples,  Prev: Backtracking,  Up: Instrumenting Macro Calls
  215. Specification Examples
  216. ......................
  217.    It may be easier to understand Edebug specifications by studying the
  218. examples provided here.
  219.    A `let' special form has a sequence of bindings and a body.  Each of
  220. the bindings is either a symbol or a sublist with a symbol and optional
  221. value.  In the specification below, notice the `gate' inside of the
  222. sublist to prevent backtracking once a sublist is found.
  223.      (def-edebug-spec let
  224.        ((&rest
  225.          &or symbolp (gate symbolp &optional form))
  226.         body))
  227.    Edebug uses the following specifications for `defun' and `defmacro'
  228. and the associated argument list and `interactive' specifications.  It
  229. is necessary to handle interactive forms specially since an expression
  230. argument it is actually evaluated outside of the function body.
  231.      (def-edebug-spec defmacro defun) ; Indirect ref to `defun' spec.
  232.      (def-edebug-spec defun
  233.        (&define name lambda-list
  234.                 [&optional stringp]   ; Match the doc string, if present.
  235.                 [&optional ("interactive" interactive)]
  236.                 def-body))
  237.      
  238.      (def-edebug-spec lambda-list
  239.        (([&rest arg]
  240.          [&optional ["&optional" arg &rest arg]]
  241.          &optional ["&rest" arg]
  242.          )))
  243.      
  244.      (def-edebug-spec interactive
  245.        (&optional &or stringp def-form))    ; Notice: `def-form'
  246.    The specification for backquote below illustrates how to match
  247. dotted lists and use `nil' to terminate recursion.  It also illustrates
  248. how components of a vector may be matched.  (The actual specification
  249. defined by Edebug does not support dotted lists because doing so causes
  250. very deep recursion that could fail.)
  251.      (def-edebug-spec ` (backquote-form))   ; Alias just for clarity.
  252.      
  253.      (def-edebug-spec backquote-form
  254.        (&or ([&or "," ",@"] &or ("quote" backquote-form) form)
  255.             (backquote-form . [&or nil backquote-form])
  256.             (vector &rest backquote-form)
  257.             sexp))
  258. File: elisp,  Node: Edebug Options,  Prev: Instrumenting Macro Calls,  Up: Edebug
  259. Edebug Options
  260. --------------
  261.    These options affect the behavior of Edebug:
  262.  - User Option: edebug-setup-hook
  263.      Functions to call before Edebug is used.  Each time it is set to a
  264.      new value, Edebug will call those functions once and then
  265.      `edebug-setup-hook' is reset to `nil'.  You could use this to load
  266.      up Edebug specifications associated with a package you are using
  267.      but only when you also use Edebug.  *Note Instrumenting::.
  268.  - User Option: edebug-all-defs
  269.      If this is non-`nil', normal evaluation of defining forms such as
  270.      `defun' and `defmacro' instruments them for Edebug.  This applies
  271.      to `eval-defun', `eval-region', `eval-buffer', and
  272.      `eval-current-buffer'.
  273.      Use the command `M-x edebug-all-defs' to toggle the value of this
  274.      option.  *Note Instrumenting::.
  275.  - User Option: edebug-all-forms
  276.      If this is non-`nil', the commands `eval-defun', `eval-region',
  277.      `eval-buffer', and `eval-current-buffer' instrument all forms,
  278.      even those that don't define anything.  This doesn't apply to
  279.      loading or evaluations in the minibuffer.
  280.      Use the command `M-x edebug-all-forms' to toggle the value of this
  281.      option.  *Note Instrumenting::.
  282.  - User Option: edebug-save-windows
  283.      If this is non-`nil', Edebug saves and restores the window
  284.      configuration.  That takes some time, so if your program does not
  285.      care what happens to the window configurations, it is better to
  286.      set this variable to `nil'.
  287.      If the value is a list, only the listed windows are saved and
  288.      restored.
  289.      You can use the `W' command in Edebug to change this variable
  290.      interactively.  *Note Edebug Display Update::.
  291.  - User Option: edebug-save-displayed-buffer-points
  292.      If this is non-`nil', Edebug saves and restores point in all
  293.      displayed buffers.
  294.      Saving and restoring point in other buffers is necessary if you are
  295.      debugging code that changes the point of a buffer which is
  296.      displayed in a non-selected window.  If Edebug or the user then
  297.      selects the window, point in that buffer will move to the window's
  298.      value of point.
  299.      Saving and restoring point in all buffers is expensive, since it
  300.      requires selecting each window twice, so enable this only if you
  301.      need it.  *Note Edebug Display Update::.
  302.  - User Option: edebug-initial-mode
  303.      If this variable is non-`nil', it specifies the initial execution
  304.      mode for Edebug when it is first activated.  Possible values are
  305.      `step', `next', `go', `Go-nonstop', `trace', `Trace-fast',
  306.      `continue', and `Continue-fast'.
  307.      The default value is `step'.  *Note Edebug Execution Modes::.
  308.  - User Option: edebug-trace
  309.      Non-`nil' means display a trace of function entry and exit.
  310.      Tracing output is displayed in a buffer named `*edebug-trace*', one
  311.      function entry or exit per line, indented by the recursion level.
  312.      The default value is `nil'.
  313.      Also see `edebug-tracing', in *Note Trace Buffer::.
  314.  - User Option: edebug-test-coverage
  315.      If non-`nil', Edebug tests coverage of all expressions debugged.
  316.      This is done by comparing the result of each expression with the
  317.      previous result. Coverage is considered OK if two different
  318.      results are found.  So to sufficiently test the coverage of your
  319.      code, try to execute it under conditions that evaluate all
  320.      expressions more than once, and produce different results for each
  321.      expression.
  322.      Use `M-x edebug-display-freq-count' to display the frequency count
  323.      and coverage information for a definition.  *Note Coverage
  324.      Testing::.
  325.  - User Option: edebug-continue-kbd-macro
  326.      If non-`nil', continue defining or executing any keyboard macro
  327.      that is executing outside of Edebug.   Use this with caution since
  328.      it is not debugged.  *Note Edebug Execution Modes::.
  329.  - User Option: edebug-print-length
  330.      If non-`nil', bind `print-length' to this while printing results
  331.      in Edebug.  The default value is `50'.  *Note Printing in Edebug::.
  332.  - User Option: edebug-print-level
  333.      If non-`nil', bind `print-level' to this while printing results in
  334.      Edebug.  The default value is `50'.
  335.  - User Option: edebug-print-circle
  336.      If non-`nil', bind `print-circle' to this while printing results
  337.      in Edebug.  The default value is `nil'.
  338.  - User Option: edebug-on-error
  339.      Edebug binds `debug-on-error' to this value, if `debug-on-error'
  340.      was previously `nil'.  *Note Trapping Errors::.
  341.  - User Option: edebug-on-quit
  342.      Edebug binds `debug-on-quit' to this value, if `debug-on-quit' was
  343.      previously `nil'.  *Note Trapping Errors::.
  344.    If you change the values of `edebug-on-error' or `edebug-on-quit'
  345. while Edebug is active, their values won't be used until the *next*
  346. time Edebug is invoked via a new command.
  347.  - User Option: edebug-global-break-condition
  348.      If non-`nil', an expression to test for at every stop point.  If
  349.      the result is non-nil, then break.  Errors are ignored.  *Note
  350.      Global Break Condition::.
  351. File: elisp,  Node: Read and Print,  Next: Minibuffers,  Prev: Debugging,  Up: Top
  352. Reading and Printing Lisp Objects
  353. *********************************
  354.    "Printing" and "reading" are the operations of converting Lisp
  355. objects to textual form and vice versa.  They use the printed
  356. representations and read syntax described in *Note Lisp Data Types::.
  357.    This chapter describes the Lisp functions for reading and printing.
  358. It also describes "streams", which specify where to get the text (if
  359. reading) or where to put it (if printing).
  360. * Menu:
  361. * Streams Intro::     Overview of streams, reading and printing.
  362. * Input Streams::     Various data types that can be used as input streams.
  363. * Input Functions::   Functions to read Lisp objects from text.
  364. * Output Streams::    Various data types that can be used as output streams.
  365. * Output Functions::  Functions to print Lisp objects as text.
  366. * Output Variables::  Variables that control what the printing functions do.
  367. File: elisp,  Node: Streams Intro,  Next: Input Streams,  Up: Read and Print
  368. Introduction to Reading and Printing
  369. ====================================
  370.    "Reading" a Lisp object means parsing a Lisp expression in textual
  371. form and producing a corresponding Lisp object.  This is how Lisp
  372. programs get into Lisp from files of Lisp code.  We call the text the
  373. "read syntax" of the object.  For example, the text `(a . 5)' is the
  374. read syntax for a cons cell whose CAR is `a' and whose CDR is the
  375. number 5.
  376.    "Printing" a Lisp object means producing text that represents that
  377. object--converting the object to its printed representation.  Printing
  378. the cons cell described above produces the text `(a . 5)'.
  379.    Reading and printing are more or less inverse operations: printing
  380. the object that results from reading a given piece of text often
  381. produces the same text, and reading the text that results from printing
  382. an object usually produces a similar-looking object.  For example,
  383. printing the symbol `foo' produces the text `foo', and reading that text
  384. returns the symbol `foo'.  Printing a list whose elements are `a' and
  385. `b' produces the text `(a b)', and reading that text produces a list
  386. (but not the same list) with elements `a' and `b'.
  387.    However, these two operations are not precisely inverses.  There are
  388. three kinds of exceptions:
  389.    * Printing can produce text that cannot be read.  For example,
  390.      buffers, windows, frames, subprocesses and markers print into text
  391.      that starts with `#'; if you try to read this text, you get an
  392.      error.  There is no way to read those data types.
  393.    * One object can have multiple textual representations.  For example,
  394.      `1' and `01' represent the same integer, and `(a b)' and `(a .
  395.      (b))' represent the same list.  Reading will accept any of the
  396.      alternatives, but printing must choose one of them.
  397.    * Comments can appear at certain points in the middle of an object's
  398.      read sequence without affecting the result of reading it.
  399. File: elisp,  Node: Input Streams,  Next: Input Functions,  Prev: Streams Intro,  Up: Read and Print
  400. Input Streams
  401. =============
  402.    Most of the Lisp functions for reading text take an "input stream"
  403. as an argument.  The input stream specifies where or how to get the
  404. characters of the text to be read.  Here are the possible types of input
  405. stream:
  406. BUFFER
  407.      The input characters are read from BUFFER, starting with the
  408.      character directly after point.  Point advances as characters are
  409.      read.
  410. MARKER
  411.      The input characters are read from the buffer that MARKER is in,
  412.      starting with the character directly after the marker.  The marker
  413.      position advances as characters are read.  The value of point in
  414.      the buffer has no effect when the stream is a marker.
  415. STRING
  416.      The input characters are taken from STRING, starting at the first
  417.      character in the string and using as many characters as required.
  418. FUNCTION
  419.      The input characters are generated by FUNCTION, one character per
  420.      call.  Normally FUNCTION is called with no arguments, and should
  421.      return a character.
  422.      Occasionally FUNCTION is called with one argument (always a
  423.      character).  When that happens, FUNCTION should save the argument
  424.      and arrange to return it on the next call.  This is called
  425.      "unreading" the character; it happens when the Lisp reader reads
  426.      one character too many and wants to "put it back where it came
  427.      from".
  428.      `t' used as a stream means that the input is read from the
  429.      minibuffer.  In fact, the minibuffer is invoked once and the text
  430.      given by the user is made into a string that is then used as the
  431.      input stream.
  432. `nil'
  433.      `nil' supplied as an input stream means to use the value of
  434.      `standard-input' instead; that value is the "default input
  435.      stream", and must be a non-`nil' input stream.
  436. SYMBOL
  437.      A symbol as input stream is equivalent to the symbol's function
  438.      definition (if any).
  439.    Here is an example of reading from a stream that is a buffer, showing
  440. where point is located before and after:
  441.      ---------- Buffer: foo ----------
  442.      This-!- is the contents of foo.
  443.      ---------- Buffer: foo ----------
  444.      
  445.      (read (get-buffer "foo"))
  446.           => is
  447.      (read (get-buffer "foo"))
  448.           => the
  449.      
  450.      ---------- Buffer: foo ----------
  451.      This is the-!- contents of foo.
  452.      ---------- Buffer: foo ----------
  453. Note that the first read skips a space.  Reading skips any amount of
  454. whitespace preceding the significant text.
  455.    In Emacs 18, reading a symbol discarded the delimiter terminating the
  456. symbol.  Thus, point would end up at the beginning of `contents' rather
  457. than after `the'.  The Emacs 19 behavior is superior because it
  458. correctly handles input such as `bar(foo)', where the open-parenthesis
  459. that ends one object is needed as the beginning of another object.
  460.    Here is an example of reading from a stream that is a marker,
  461. initially positioned at the beginning of the buffer shown.  The value
  462. read is the symbol `This'.
  463.      ---------- Buffer: foo ----------
  464.      This is the contents of foo.
  465.      ---------- Buffer: foo ----------
  466.      
  467.      (setq m (set-marker (make-marker) 1 (get-buffer "foo")))
  468.           => #<marker at 1 in foo>
  469.      (read m)
  470.           => This
  471.      m
  472.           => #<marker at 5 in foo>   ;; Before the first space.
  473.    Here we read from the contents of a string:
  474.      (read "(When in) the course")
  475.           => (When in)
  476.    The following example reads from the minibuffer.  The prompt is:
  477. `Lisp expression: '.  (That is always the prompt used when you read
  478. from the stream `t'.)  The user's input is shown following the prompt.
  479.      (read t)
  480.           => 23
  481.      ---------- Buffer: Minibuffer ----------
  482.      Lisp expression: `23 RET'
  483.      ---------- Buffer: Minibuffer ----------
  484.    Finally, here is an example of a stream that is a function, named
  485. `useless-stream'.  Before we use the stream, we initialize the variable
  486. `useless-list' to a list of characters.  Then each call to the function
  487. `useless-stream' obtains the next character in the list or unreads a
  488. character by adding it to the front of the list.
  489.      (setq useless-list (append "XY()" nil))
  490.           => (88 89 40 41)
  491.      
  492.      (defun useless-stream (&optional unread)
  493.        (if unread
  494.            (setq useless-list (cons unread useless-list))
  495.          (prog1 (car useless-list)
  496.                 (setq useless-list (cdr useless-list)))))
  497.           => useless-stream
  498. Now we read using the stream thus constructed:
  499.      (read 'useless-stream)
  500.           => XY
  501.      
  502.      useless-list
  503.           => (40 41)
  504. Note that the open and close parentheses remains in the list.  The Lisp
  505. reader encountered the open parenthesis, decided that it ended the
  506. input, and unread it.  Another attempt to read from the stream at this
  507. point would read `()' and return `nil'.
  508.  - Function: get-file-char
  509.      This function is used internally as an input stream to read from
  510.      the input file opened by the function `load'.  Don't use this
  511.      function yourself.
  512. File: elisp,  Node: Input Functions,  Next: Output Streams,  Prev: Input Streams,  Up: Read and Print
  513. Input Functions
  514. ===============
  515.    This section describes the Lisp functions and variables that pertain
  516. to reading.
  517.    In the functions below, STREAM stands for an input stream (see the
  518. previous section).  If STREAM is `nil' or omitted, it defaults to the
  519. value of `standard-input'.
  520.    An `end-of-file' error is signaled if reading encounters an
  521. unterminated list, vector, or string.
  522.  - Function: read &optional STREAM
  523.      This function reads one textual Lisp expression from STREAM,
  524.      returning it as a Lisp object.  This is the basic Lisp input
  525.      function.
  526.  - Function: read-from-string STRING &optional START END
  527.      This function reads the first textual Lisp expression from the
  528.      text in STRING.  It returns a cons cell whose CAR is that
  529.      expression, and whose CDR is an integer giving the position of the
  530.      next remaining character in the string (i.e., the first one not
  531.      read).
  532.      If START is supplied, then reading begins at index START in the
  533.      string (where the first character is at index 0).  If END is also
  534.      supplied, then reading stops just before that index, as if the rest
  535.      of the string were not there.
  536.      For example:
  537.           (read-from-string "(setq x 55) (setq y 5)")
  538.                => ((setq x 55) . 11)
  539.           (read-from-string "\"A short string\"")
  540.                => ("A short string" . 16)
  541.           
  542.           ;; Read starting at the first character.
  543.           (read-from-string "(list 112)" 0)
  544.                => ((list 112) . 10)
  545.           ;; Read starting at the second character.
  546.           (read-from-string "(list 112)" 1)
  547.                => (list . 5)
  548.           ;; Read starting at the seventh character,
  549.           ;;   and stopping at the ninth.
  550.           (read-from-string "(list 112)" 6 8)
  551.                => (11 . 8)
  552.  - Variable: standard-input
  553.      This variable holds the default input stream--the stream that
  554.      `read' uses when the STREAM argument is `nil'.
  555. File: elisp,  Node: Output Streams,  Next: Output Functions,  Prev: Input Functions,  Up: Read and Print
  556. Output Streams
  557. ==============
  558.    An output stream specifies what to do with the characters produced
  559. by printing.  Most print functions accept an output stream as an
  560. optional argument.  Here are the possible types of output stream:
  561. BUFFER
  562.      The output characters are inserted into BUFFER at point.  Point
  563.      advances as characters are inserted.
  564. MARKER
  565.      The output characters are inserted into the buffer that MARKER
  566.      points into, at the marker position.  The marker position advances
  567.      as characters are inserted.  The value of point in the buffer has
  568.      no effect on printing when the stream is a marker.
  569. FUNCTION
  570.      The output characters are passed to FUNCTION, which is responsible
  571.      for storing them away.  It is called with a single character as
  572.      argument, as many times as there are characters to be output, and
  573.      is free to do anything at all with the characters it receives.
  574.      The output characters are displayed in the echo area.
  575. `nil'
  576.      `nil' specified as an output stream means to the value of
  577.      `standard-output' instead; that value is the "default output
  578.      stream", and must be a non-`nil' output stream.
  579. SYMBOL
  580.      A symbol as output stream is equivalent to the symbol's function
  581.      definition (if any).
  582.    Many of the valid output streams are also valid as input streams.
  583. The difference between input and output streams is therefore mostly one
  584. of how you use a Lisp object, not a distinction of types of object.
  585.    Here is an example of a buffer used as an output stream.  Point is
  586. initially located as shown immediately before the `h' in `the'.  At the
  587. end, point is located directly before that same `h'.
  588.      (setq m (set-marker (make-marker) 10 (get-buffer "foo")))
  589.           => #<marker at 10 in foo>
  590.      
  591.      ---------- Buffer: foo ----------
  592.      This is t-!-he contents of foo.
  593.      ---------- Buffer: foo ----------
  594.      
  595.      (print "This is the output" (get-buffer "foo"))
  596.           => "This is the output"
  597.      
  598.      m
  599.           => #<marker at 32 in foo>
  600.      ---------- Buffer: foo ----------
  601.      This is t
  602.      "This is the output"
  603.      -!-he contents of foo.
  604.      ---------- Buffer: foo ----------
  605.    Now we show a use of a marker as an output stream.  Initially, the
  606. marker is in buffer `foo', between the `t' and the `h' in the word
  607. `the'.  At the end, the marker has advanced over the inserted text so
  608. that it remains positioned before the same `h'.  Note that the location
  609. of point, shown in the usual fashion, has no effect.
  610.      ---------- Buffer: foo ----------
  611.      "This is the -!-output"
  612.      ---------- Buffer: foo ----------
  613.      
  614.      m
  615.           => #<marker at 11 in foo>
  616.      
  617.      (print "More output for foo." m)
  618.           => "More output for foo."
  619.      
  620.      ---------- Buffer: foo ----------
  621.      "This is t
  622.      "More output for foo."
  623.      he -!-output"
  624.      ---------- Buffer: foo ----------
  625.      
  626.      m
  627.           => #<marker at 35 in foo>
  628.    The following example shows output to the echo area:
  629.      (print "Echo Area output" t)
  630.           => "Echo Area output"
  631.      ---------- Echo Area ----------
  632.      "Echo Area output"
  633.      ---------- Echo Area ----------
  634.    Finally, we show the use of a function as an output stream.  The
  635. function `eat-output' takes each character that it is given and conses
  636. it onto the front of the list `last-output' (*note Building Lists::.).
  637. At the end, the list contains all the characters output, but in reverse
  638. order.
  639.      (setq last-output nil)
  640.           => nil
  641.      
  642.      (defun eat-output (c)
  643.        (setq last-output (cons c last-output)))
  644.           => eat-output
  645.      
  646.      (print "This is the output" 'eat-output)
  647.           => "This is the output"
  648.      
  649.      last-output
  650.           => (10 34 116 117 112 116 117 111 32 101 104
  651.          116 32 115 105 32 115 105 104 84 34 10)
  652. Now we can put the output in the proper order by reversing the list:
  653.      (concat (nreverse last-output))
  654.           => "
  655.      \"This is the output\"
  656.      "
  657. Calling `concat' converts the list to a string so you can see its
  658. contents more clearly.
  659. File: elisp,  Node: Output Functions,  Next: Output Variables,  Prev: Output Streams,  Up: Read and Print
  660. Output Functions
  661. ================
  662.    This section describes the Lisp functions for printing Lisp objects.
  663.    Some of the Emacs printing functions add quoting characters to the
  664. output when necessary so that it can be read properly.  The quoting
  665. characters used are `"' and `\'; they distinguish strings from symbols,
  666. and prevent punctuation characters in strings and symbols from being
  667. taken as delimiters when reading.  *Note Printed Representation::, for
  668. full details.  You specify quoting or no quoting by the choice of
  669. printing function.
  670.    If the text is to be read back into Lisp, then it is best to print
  671. with quoting characters to avoid ambiguity.  Likewise, if the purpose is
  672. to describe a Lisp object clearly for a Lisp programmer.  However, if
  673. the purpose of the output is to look nice for humans, then it is better
  674. to print without quoting.
  675.    Printing a self-referent Lisp object requires an infinite amount of
  676. text.  In certain cases, trying to produce this text leads to a stack
  677. overflow.  Emacs detects such recursion and prints `#LEVEL' instead of
  678. recursively printing an object already being printed.  For example,
  679. here `#0' indicates a recursive reference to the object at level 0 of
  680. the current print operation:
  681.      (setq foo (list nil))
  682.           => (nil)
  683.      (setcar foo foo)
  684.           => (#0)
  685.    In the functions below, STREAM stands for an output stream.  (See
  686. the previous section for a description of output streams.)  If STREAM
  687. is `nil' or omitted, it defaults to the value of `standard-output'.
  688.  - Function: print OBJECT &optional STREAM
  689.      The `print' function is a convenient way of printing.  It outputs
  690.      the printed representation of OBJECT to STREAM, printing in
  691.      addition one newline before OBJECT and another after it.  Quoting
  692.      characters are used.  `print' returns OBJECT.  For example:
  693.           (progn (print 'The\ cat\ in)
  694.                  (print "the hat")
  695.                  (print " came back"))
  696.                -|
  697.                -| The\ cat\ in
  698.                -|
  699.                -| "the hat"
  700.                -|
  701.                -| " came back"
  702.                -|
  703.                => " came back"
  704.  - Function: prin1 OBJECT &optional STREAM
  705.      This function outputs the printed representation of OBJECT to
  706.      STREAM.  It does not print newlines to separate output as `print'
  707.      does, but it does use quoting characters just like `print'.  It
  708.      returns OBJECT.
  709.           (progn (prin1 'The\ cat\ in)
  710.                  (prin1 "the hat")
  711.                  (prin1 " came back"))
  712.                -| The\ cat\ in"the hat"" came back"
  713.                => " came back"
  714.  - Function: princ OBJECT &optional STREAM
  715.      This function outputs the printed representation of OBJECT to
  716.      STREAM.  It returns OBJECT.
  717.      This function is intended to produce output that is readable by
  718.      people, not by `read', so it doesn't insert quoting characters and
  719.      doesn't put double-quotes around the contents of strings.  It does
  720.      not add any spacing between calls.
  721.           (progn
  722.             (princ 'The\ cat)
  723.             (princ " in the \"hat\""))
  724.                -| The cat in the "hat"
  725.                => " in the \"hat\""
  726.  - Function: terpri &optional STREAM
  727.      This function outputs a newline to STREAM.  The name stands for
  728.      "terminate print".
  729.  - Function: write-char CHARACTER &optional STREAM
  730.      This function outputs CHARACTER to STREAM.  It returns CHARACTER.
  731.  - Function: prin1-to-string OBJECT &optional NOESCAPE
  732.      This function returns a string containing the text that `prin1'
  733.      would have printed for the same argument.
  734.           (prin1-to-string 'foo)
  735.                => "foo"
  736.           (prin1-to-string (mark-marker))
  737.                => "#<marker at 2773 in strings.texi>"
  738.      If NOESCAPE is non-`nil', that inhibits use of quoting characters
  739.      in the output.  (This argument is supported in Emacs versions 19
  740.      and later.)
  741.           (prin1-to-string "foo")
  742.                => "\"foo\""
  743.           (prin1-to-string "foo" t)
  744.                => "foo"
  745.      See `format', in *Note String Conversion::, for other ways to
  746.      obtain the printed representation of a Lisp object as a string.
  747. File: elisp,  Node: Output Variables,  Prev: Output Functions,  Up: Read and Print
  748. Variables Affecting Output
  749. ==========================
  750.  - Variable: standard-output
  751.      The value of this variable is the default output stream--the stream
  752.      that print functions use when the STREAM argument is `nil'.
  753.  - Variable: print-escape-newlines
  754.      If this variable is non-`nil', then newline characters in strings
  755.      are printed as `\n' and formfeeds are printed as `\f'.  Normally
  756.      these characters are printed as actual newlines and formfeeds.
  757.      This variable affects the print functions `prin1' and `print', as
  758.      well as everything that uses them.  It does not affect `princ'.
  759.      Here is an example using `prin1':
  760.           (prin1 "a\nb")
  761.                -| "a
  762.                -| b"
  763.                => "a
  764.           b"
  765.           
  766.           (let ((print-escape-newlines t))
  767.             (prin1 "a\nb"))
  768.                -| "a\nb"
  769.                => "a
  770.           b"
  771.      In the second expression, the local binding of
  772.      `print-escape-newlines' is in effect during the call to `prin1',
  773.      but not during the printing of the result.
  774.  - Variable: print-length
  775.      The value of this variable is the maximum number of elements of a
  776.      list, vector or bitvector that will be printed.  If an object
  777.      being printed has more than this many elements, it is abbreviated
  778.      with an ellipsis.
  779.      If the value is `nil' (the default), then there is no limit.
  780.           (setq print-length 2)
  781.                => 2
  782.           (print '(1 2 3 4 5))
  783.                -| (1 2 ...)
  784.                => (1 2 ...)
  785.  - Variable: print-level
  786.      The value of this variable is the maximum depth of nesting of
  787.      parentheses and brackets when printed.  Any list or vector at a
  788.      depth exceeding this limit is abbreviated with an ellipsis.  A
  789.      value of `nil' (which is the default) means no limit.
  790.      This variable exists in version 19 and later versions.
  791. File: elisp,  Node: Minibuffers,  Next: Command Loop,  Prev: Read and Print,  Up: Top
  792. Minibuffers
  793. ***********
  794.    A "minibuffer" is a special buffer that Emacs commands use to read
  795. arguments more complicated than the single numeric prefix argument.
  796. These arguments include file names, buffer names, and command names (as
  797. in `M-x').  The minibuffer is displayed on the bottom line of the
  798. screen, in the same place as the echo area, but only while it is in use
  799. for reading an argument.
  800. * Menu:
  801. * Intro to Minibuffers::      Basic information about minibuffers.
  802. * Text from Minibuffer::      How to read a straight text string.
  803. * Object from Minibuffer::    How to read a Lisp object or expression.
  804. * Minibuffer History::          Recording previous minibuffer inputs
  805.                 so the user can reuse them.
  806. * Completion::                How to invoke and customize completion.
  807. * Yes-or-No Queries::         Asking a question with a simple answer.
  808. * Multiple Queries::          Asking a series of similar questions.
  809. * Minibuffer Misc::           Various customization hooks and variables.
  810. File: elisp,  Node: Intro to Minibuffers,  Next: Text from Minibuffer,  Up: Minibuffers
  811. Introduction to Minibuffers
  812. ===========================
  813.    In most ways, a minibuffer is a normal Emacs buffer.  Most operations
  814. *within* a buffer, such as editing commands, work normally in a
  815. minibuffer.  However, many operations for managing buffers do not apply
  816. to minibuffers.  The name of a minibuffer always has the form
  817. ` *Minibuf-NUMBER', and it cannot be changed.  Minibuffers are
  818. displayed only in special windows used only for minibuffers; these
  819. windows always appear at the bottom of a frame.  (Sometime frames have
  820. no minibuffer window, and sometimes a special kind of frame contains
  821. nothing but a minibuffer window; see *Note Minibuffers and Frames::.)
  822.    The minibuffer's window is normally a single line.  You can resize it
  823. temporarily with the window sizing commands; it reverts to its normal
  824. size when the minibuffer is exited.  You can resize it permanently by
  825. using the window sizing commands in the frame's other window, when the
  826. minibuffer is not active.  If the frame contains just a minibuffer, you
  827. can change the minibuffer's size by changing the frame's size.
  828.    If a command uses a minibuffer while there is an active minibuffer,
  829. this is called a "recursive minibuffer".  The first minibuffer is named
  830. ` *Minibuf-0*'.  Recursive minibuffers are named by incrementing the
  831. number at the end of the name.  (The names begin with a space so that
  832. they won't show up in normal buffer lists.)  Of several recursive
  833. minibuffers, the innermost (or most recently entered) is the active
  834. minibuffer.  We usually call this "the" minibuffer.  You can permit or
  835. forbid recursive minibuffers by setting the variable
  836. `enable-recursive-minibuffers' or by putting properties of that name on
  837. command symbols (*note Minibuffer Misc::.).
  838.    Like other buffers, a minibuffer may use any of several local keymaps
  839. (*note Keymaps::.); these contain various exit commands and in some
  840. cases completion commands (*note Completion::.).
  841.    * `minibuffer-local-map' is for ordinary input (no completion).
  842.    * `minibuffer-local-ns-map' is similar, except that SPC exits just
  843.      like RET.  This is used mainly for Mocklisp compatibility.
  844.    * `minibuffer-local-completion-map' is for permissive completion.
  845.    * `minibuffer-local-must-match-map' is for strict completion and for
  846.      cautious completion.
  847. File: elisp,  Node: Text from Minibuffer,  Next: Object from Minibuffer,  Prev: Intro to Minibuffers,  Up: Minibuffers
  848. Reading Text Strings with the Minibuffer
  849. ========================================
  850.    Most often, the minibuffer is used to read text as a string.  It can
  851. also be used to read a Lisp object in textual form.  The most basic
  852. primitive for minibuffer input is `read-from-minibuffer'; it can do
  853. either one.
  854.    In most cases, you should not call minibuffer input functions in the
  855. middle of a Lisp function.  Instead, do all minibuffer input as part of
  856. reading the arguments for a command, in the `interactive' spec.  *Note
  857. Defining Commands::.
  858.  - Function: read-from-minibuffer PROMPT-STRING &optional
  859.           INITIAL-CONTENTS KEYMAP READ HIST
  860.      This function is the most general way to get input through the
  861.      minibuffer.  By default, it accepts arbitrary text and returns it
  862.      as a string; however, if READ is non-`nil', then it uses `read' to
  863.      convert the text into a Lisp object (*note Input Functions::.).
  864.      The first thing this function does is to activate a minibuffer and
  865.      display it with PROMPT-STRING as the prompt.  This value must be a
  866.      string.
  867.      Then, if INITIAL-CONTENTS is a string, `read-from-minibuffer'
  868.      inserts it into the minibuffer, leaving point at the end.  The
  869.      minibuffer appears with this text as its contents.
  870.      The value of INITIAL-CONTENTS may also be a cons cell of the form
  871.      `(STRING . POSITION)'.  This means to insert STRING in the
  872.      minibuffer but put point POSITION characters from the beginning,
  873.      rather than at the end.
  874.      If KEYMAP is non-`nil', that keymap is the local keymap to use in
  875.      the minibuffer.  If KEYMAP is omitted or `nil', the value of
  876.      `minibuffer-local-map' is used as the keymap.  Specifying a keymap
  877.      is the most important way to customize the minibuffer for various
  878.      applications such as completion.
  879.      The argument HIST specifies which history list variable to use for
  880.      saving the input and for history commands used in the minibuffer.
  881.      It defaults to `minibuffer-history'.  *Note Minibuffer History::.
  882.      When the user types a command to exit the minibuffer,
  883.      `read-from-minibuffer' uses the text in the minibuffer to produce
  884.      its return value.  Normally it simply makes a string containing
  885.      that text.  However, if READ is non-`nil', `read-from-minibuffer'
  886.      reads the text and returns the resulting Lisp object, unevaluated.
  887.      (*Note Input Functions::, for information about reading.)
  888.  - Function: read-string PROMPT &optional INITIAL
  889.      This function reads a string from the minibuffer and returns it.
  890.      The arguments PROMPT and INITIAL are used as in
  891.      `read-from-minibuffer'.  The keymap used is `minibuffer-local-map'.
  892.      This is a simplified interface to the `read-from-minibuffer'
  893.      function:
  894.           (read-string PROMPT INITIAL)
  895.           ==
  896.           (read-from-minibuffer PROMPT INITIAL nil nil nil)
  897.  - Variable: minibuffer-local-map
  898.      This is the default local keymap for reading from the minibuffer.
  899.      By default, it makes the following bindings:
  900.     LFD
  901.           `exit-minibuffer'
  902.     RET
  903.           `exit-minibuffer'
  904.     `C-g'
  905.           `abort-recursive-edit'
  906.     `M-n'
  907.           `next-history-element'
  908.     `M-p'
  909.           `previous-history-element'
  910.     `M-r'
  911.           `next-matching-history-element'
  912.     `M-s'
  913.           `previous-matching-history-element'
  914.  - Function: read-no-blanks-input PROMPT &optional INITIAL
  915.      This function reads a string from the minibuffer, but does not
  916.      allow whitespace characters as part of the input: instead, those
  917.      characters terminate the input.  The arguments PROMPT and INITIAL
  918.      are used as in `read-from-minibuffer'.
  919.      This is a simplified interface to the `read-from-minibuffer'
  920.      function, and passes the value of the `minibuffer-local-ns-map'
  921.      keymap as the KEYMAP argument for that function.  Since the keymap
  922.      `minibuffer-local-ns-map' does not rebind `C-q', it *is* possible
  923.      to put a space into the string, by quoting it.
  924.           (read-no-blanks-input PROMPT INITIAL)
  925.           ==
  926.           (read-from-minibuffer PROMPT INITIAL minibuffer-local-ns-map)
  927.  - Variable: minibuffer-local-ns-map
  928.      This built-in variable is the keymap used as the minibuffer local
  929.      keymap in the function `read-no-blanks-input'.  By default, it
  930.      makes the following bindings, in addition to those of
  931.      `minibuffer-local-map':
  932.     SPC
  933.           `exit-minibuffer'
  934.     TAB
  935.           `exit-minibuffer'
  936.     `?'
  937.           `self-insert-and-exit'
  938. File: elisp,  Node: Object from Minibuffer,  Next: Minibuffer History,  Prev: Text from Minibuffer,  Up: Minibuffers
  939. Reading Lisp Objects with the Minibuffer
  940. ========================================
  941.    This section describes functions for reading Lisp objects with the
  942. minibuffer.
  943.  - Function: read-minibuffer PROMPT &optional INITIAL
  944.      This function reads a Lisp object in the minibuffer and returns it,
  945.      without evaluating it.  The arguments PROMPT and INITIAL are used
  946.      as in `read-from-minibuffer'.
  947.      This is a simplified interface to the `read-from-minibuffer'
  948.      function:
  949.           (read-minibuffer PROMPT INITIAL)
  950.           ==
  951.           (read-from-minibuffer PROMPT INITIAL nil t)
  952.      Here is an example in which we supply the string `"(testing)"' as
  953.      initial input:
  954.           (read-minibuffer
  955.            "Enter an expression: " (format "%s" '(testing)))
  956.           
  957.           ;; Here is how the minibuffer is displayed:
  958.           ---------- Buffer: Minibuffer ----------
  959.           Enter an expression: (testing)-!-
  960.           ---------- Buffer: Minibuffer ----------
  961.      The user can type RET immediately to use the initial input as a
  962.      default, or can edit the input.
  963.  - Function: eval-minibuffer PROMPT &optional INITIAL
  964.      This function reads a Lisp expression in the minibuffer, evaluates
  965.      it, then returns the result.  The arguments PROMPT and INITIAL are
  966.      used as in `read-from-minibuffer'.
  967.      This function simply evaluates the result of a call to
  968.      `read-minibuffer':
  969.           (eval-minibuffer PROMPT INITIAL)
  970.           ==
  971.           (eval (read-minibuffer PROMPT INITIAL))
  972.  - Function: edit-and-eval-command PROMPT FORM
  973.      This function reads a Lisp expression in the minibuffer, and then
  974.      evaluates it.  The difference between this command and
  975.      `eval-minibuffer' is that here the initial FORM is not optional
  976.      and it is treated as a Lisp object to be converted to printed
  977.      representation rather than as a string of text.  It is printed with
  978.      `prin1', so if it is a string, double-quote characters (`"')
  979.      appear in the initial text.  *Note Output Functions::.
  980.      The first thing `edit-and-eval-command' does is to activate the
  981.      minibuffer with PROMPT as the prompt.  Then it inserts the printed
  982.      representation of FORM in the minibuffer, and lets the user edit.
  983.      When the user exits the minibuffer, the edited text is read with
  984.      `read' and then evaluated.  The resulting value becomes the value
  985.      of `edit-and-eval-command'.
  986.      In the following example, we offer the user an expression with
  987.      initial text which is a valid form already:
  988.           (edit-and-eval-command "Please edit: " '(forward-word 1))
  989.           
  990.           ;; After evaluation of the preceding expression,
  991.           ;;   the following appears in the minibuffer:
  992.           ---------- Buffer: Minibuffer ----------
  993.           Please edit: (forward-word 1)-!-
  994.           ---------- Buffer: Minibuffer ----------
  995.      Typing RET right away would exit the minibuffer and evaluate the
  996.      expression, thus moving point forward one word.
  997.      `edit-and-eval-command' returns `nil' in this example.
  998.